import Request from "./Request"
const citys={
    provinceList:[],
    citysList:[],
    async init(){
        if(this.provinceList.length>0){
            return;
        }
        let res = await Request.post("exclude", "GetProvince");
        if(res.code==0){
            this.provinceList = [];
            this.citysList = [];
            let proObj={};
            if(res.data.provinceList != null && res.data.cityList != null){
                res.data.provinceList.forEach(pro=>{
                    proObj[pro.Id] = {"id":pro.Id,"name":pro.Name,"list":[]};
                    this.provinceList.push({"id":pro.Id,"name":pro.Name})
                })
                res.data.cityList.forEach(city=>{
                    proObj[city.ParentId].list.push({"id":city.Id,"name":city.Name})
                })
                for(var key in proObj){
                    this.citysList.push(proObj[key]);
                }
            }
        }
    },
}
export default citys;